package cn.stylefeng.guns.modular.merchant.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.stylefeng.guns.modular.merchant.service.PluManagerPageService;

import cn.stylefeng.guns.core.common.annotion.Permission;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;

@Controller
@RequestMapping("/pluManagerPage")
public class PluManagerPageController extends BaseController {

    @Autowired
    private PluManagerPageService pluManagerPageService;

    private String PREFIX = "/modular/merchant/pluManager/";
	 /**
     * 跳转到菜品管理首页
     * @return
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "pluManagerPage.html";
    }
     /**
     * 获取所有菜品管理列表
     */
    @RequestMapping(value = "/list")
    @Permission
    @ResponseBody
    public Object list(@RequestParam(value = "pluCode", required = false) String pluCode,@RequestParam(value = "pluType", required = false) String pluType) {
    	Page<Map<String, Object>> list = pluManagerPageService.list(pluCode,pluType);
    	return LayuiPageFactory.createPageInfo(list);
    }
     /**
     * 跳转到添加菜品管理页面
     */
    @RequestMapping("/addPluManagerPage")
    public String getAddPage() {
        return PREFIX + "pluManagerPage_add.html";
    }


     /**
     * 跳转到编辑菜品管理页面
     */
    @RequestMapping("/updatePluManagerPage")
    public String getUpdatePage(String param) {
	    if (ToolUtil.isEmpty(param)) {
	            throw new RequestEmptyException();
	        }
        return PREFIX + "pluManagerPage_edit.html";
    }

    /**
     * 编辑查询详情
     */
    @RequestMapping(value = "/detail/{param}")
    @Permission
    @ResponseBody
    public Object detail(@PathVariable("param") String param) {
        //Dept dept = deptService.getById(deptId);
        //DeptDto deptDto = new DeptDto();
        //BeanUtil.copyProperties(dept, deptDto);
        //deptDto.setPName(ConstantFactory.me().getDeptName(deptDto.getPid()));
        //return deptDto;
        return null;
    }

    /**
     * 修改菜品管理
     */
    //@BussinessLog(value = "修改菜品管理", key = "simpleName", dict = DeptDict.class)
    @RequestMapping(value = "/update")
    @Permission
    @ResponseBody
    public ResponseData update(String param) {
        //deptService.editDept(dept);
        return SUCCESS_TIP;
    }
     /**
     * 新增菜品管理
     */
    //@BussinessLog(value = "添加菜品管理", key = "simpleName", dict = DeptDict.class)
    @RequestMapping(value = "/add")
    @Permission
    @ResponseBody
    public ResponseData add(String param) {
        pluManagerPageService.add(param);
        return SUCCESS_TIP;
    }
    /**
     * 删除菜品管理
     */
    //@BussinessLog(value = "删除菜品管理", key = "deptId", dict = DeptDict.class)
    @RequestMapping(value = "/delete")
    @Permission
    @ResponseBody
    public ResponseData delete(@RequestParam String id) {

        //缓存被删除的部门名称
        //LogObjectHolder.me().set(ConstantFactory.me().getDeptName(deptId));

        pluManagerPageService.delete(id);

        return SUCCESS_TIP;
    }
}    
